Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create custom contact properties and verify replication of those properties #244

Merged
merged 13 commits into from
Jan 25, 2024

Conversation

bhuvana-talend
Copy link
Contributor

Description of change

(https://jira.talendforge.org/browse/TDL-24145)
client.py - Method to create custom contact properties and add it to the contacts
test_hubspot_bookmarks.py - Call the create method in test data setup

Manual QA steps

Risks

Rollback steps

  • revert this branch

@bhtowles
Copy link
Contributor

bhtowles commented Dec 1, 2023

Where do these custom properties show up? I would not expect them to necessarily change bookmarks as I assume it is an add on to an existing stream since there is no update in base or streams_to_test. Should we move this to the all fields test and actually test that the custom data is being replicated? The JIRA ticket suggests that we should test that the new data is being replicated.

Copy link
Contributor

@HarrisonMarcRose HarrisonMarcRose left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

tests/client.py Outdated
try:
response = self.post(url, current_data)
LOGGER.info("response is %s", response)
except Exception as e:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Exception is too broad. We should be a specific with exceptions as possible as this will swallow any exception, some not intended here.

Also, I'm not sure why you would get an exception if data already exists instead of getting a 4xx response code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it is a 409, which was causing the test to fail. I'll handle it specifically instead of a broader one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we miscommunicated. I meant in the except Exception as e we should actually change the word Exception to a more specific exception. I don't know what kind it is but based on the 409 maybe it is an RequestException or HTTPError? However, I didn't think a 409 would actually raise an exception. If you are trying to do this until you get a successful status code maybe another way would be better. Let's talk about what you are trying to achieve to determine the best way to go about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the post call returns a response code of 409 and in post method the exception is raised. That's why I am handling it here. I can change the exception to a specific one to make it more readable.

Comment on lines +816 to +868
property = {
"name": "custom_date",
"label": "A New Date Custom Property",
"description": "A new date property for you",
"groupName": "contactinformation",
"type": "date",
"fieldType": "text",
"formField": True,
"displayOrder": 9,
"options": [
]
}
data.append(deepcopy(property))

property = {
"name": "custom_datetime",
"label": "A New Datetime Custom Property",
"description": "A new datetime property for you",
"groupName": "contactinformation",
"type": "datetime",
"fieldType": "text",
"formField": True,
"displayOrder": 10,
"options": [
]
}
data.append(deepcopy(property))

property = {
"name": "multi_pick",
"label": "multi pick",
"description": "multi select picklist test",
"groupName": "contactinformation",
"type": "enumeration",
"fieldType": "checkbox",
"hidden": False,
"options": [
{
"label": "Option A",
"value": "option_a"
},
{
"label": "Option B",
"value": "option_b"
},
{
"label": "Option C",
"value": "option_c"
}
],
"formField": True
}
data.append(deepcopy(property))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is great that you are creating a variety of data types in the custom fields. Since you went through the pain of creating them we should also use them all when creating a contact - instead of just the first two - to make sure that we support all of the types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:) was expecting this comment.. The other types seems complicated, I'll need more time to figure out how to do. Can I write a separate card for that ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure.

@bhuvana-talend
Copy link
Contributor Author

Where do these custom properties show up? I would not expect them to necessarily change bookmarks as I assume it is an add on to an existing stream since there is no update in base or streams_to_test. Should we move this to the all fields test and actually test that the custom data is being replicated? The JIRA ticket suggests that we should test that the new data is being replicated.

@bhtowles , these values are verified in all_fields test. I have verified this by checking the values in the log file manually. Currently, in all fields test we don't check any field specifically. The old contacts won't have this field, the new contacts created after these custom fields are added will have these fields. I can show and explain you. We can move this to all fields test also instead of calling from bookmark test. It is anyway, a one time task to create these fields.

Copy link
Contributor

@HarrisonMarcRose HarrisonMarcRose left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets talk about these comments

Comment on lines +816 to +868
property = {
"name": "custom_date",
"label": "A New Date Custom Property",
"description": "A new date property for you",
"groupName": "contactinformation",
"type": "date",
"fieldType": "text",
"formField": True,
"displayOrder": 9,
"options": [
]
}
data.append(deepcopy(property))

property = {
"name": "custom_datetime",
"label": "A New Datetime Custom Property",
"description": "A new datetime property for you",
"groupName": "contactinformation",
"type": "datetime",
"fieldType": "text",
"formField": True,
"displayOrder": 10,
"options": [
]
}
data.append(deepcopy(property))

property = {
"name": "multi_pick",
"label": "multi pick",
"description": "multi select picklist test",
"groupName": "contactinformation",
"type": "enumeration",
"fieldType": "checkbox",
"hidden": False,
"options": [
{
"label": "Option A",
"value": "option_a"
},
{
"label": "Option B",
"value": "option_b"
},
{
"label": "Option C",
"value": "option_c"
}
],
"formField": True
}
data.append(deepcopy(property))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure.

tests/client.py Outdated
try:
response = self.post(url, current_data)
LOGGER.info("response is %s", response)
except Exception as e:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we miscommunicated. I meant in the except Exception as e we should actually change the word Exception to a more specific exception. I don't know what kind it is but based on the 409 maybe it is an RequestException or HTTPError? However, I didn't think a 409 would actually raise an exception. If you are trying to do this until you get a successful status code maybe another way would be better. Let's talk about what you are trying to achieve to determine the best way to go about it.

Comment on lines +948 to +955
{
"property": "custom_string",
"value": "custom_string_value"
},
{
"property": "custom_number",
"value": 1567
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are setting custom properties for every call of create_contacts we need the create_custom_contact_properties to be called prior to calling the create_contacts. I see you are doing this in the test, but what about other tests that would need to add contacts, those would probably break if the custom properties were not present. I believe we should call create_custom_contact_properties in the __init__ of the client so that we call it once when it starts up instead of depending on the tester to know about this or remember to add it in each test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, creating the custom contact property is a one time task. After my first successful run of the test, it never creates and gives a 409, that's why I am skipping it. Probably doing it in init is a good idea. Will try that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you moved it to setup. I meant the init of the client so anyone using the client makes sure it is in good shape, vs just for your test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, moved it to init

tests/client.py Outdated
Comment on lines 931 to 936
except Exception as DataAlreadyExistsExcp:
LOGGER.info("Data already exists for %s", current_data)
if '409' in str(DataAlreadyExistsExcp):
pass
else:
response.raise_for_status()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I"m communicating well enough. doing except Exception is a no-no as this is a very broad exception. We need to figure out the specific exception that is being thrown and catch that. To determine what exception is being thrown you can remove the try/except and run the test to see what exception is raised. Catch that one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exception can be used as a wildcard that catches (almost) everything. However, it is good practice to be as specific as possible with the types of exceptions that we intend to handle, and to allow any unexpected exceptions to propagate on.

https://docs.python.org/3/tutorial/errors.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry Harrison - I think I got it right now :) Now handling it as requests.exceptions.HTTPError

@bhuvana-talend bhuvana-talend merged commit 685a827 into master Jan 25, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants